import { da } from "element-plus/es/locale";
import { defineAsyncComponent } from "vue";
import { RouteRecordRaw, RouteRecordName, RouteLocationNormalized } from "vue-router";
import router, { routes } from "../router";
import { MainStore } from "../stroe";
import request from "../utils/request";
import { Menu } from "./entity/Menu";

export const getMenu = () => {
  return request<Menu>({
    method: 'POST',
    url: '/admin/data/menu'
  })
}

export const AddRouter = async () => {
  let data:any = await getMenu();
  data.forEach((v:any)=>{
    let routerlist:RouteRecordRaw={
      path:v.path,
      name:v.name,
      component:()=>import(`../view/${v.path}.vue`),
      children:v.children
    }
   router.addRoute(routerlist)
  }
  )
}


